//
//  AddressCell.swift
//  demo
//
//  Created by toro宇 on 2020/2/22.
//  Copyright © 2020 CodeYu. All rights reserved.
//

import UIKit

class AddressCell: UITableViewCell {
    typealias BtnBlock = () -> Void
    
    var deleteBlock: BtnBlock?
    
    let bgView:UIView = {
        let view = UIView()
        view.backgroundColor = UIColor.white
        view.layer.masksToBounds = true
        view.layer.cornerRadius = 6
        return view
    }()
    let nameLab: UILabel = {
        let lab = UILabel()
        lab.textColor = UIColor.black
        lab.font = UIFont.systemFont(ofSize: 14)
        return lab
    }()
    let phoneLab:UILabel = {
        let lab = UILabel()
        lab.textColor = UIColor.black
        lab.font = UIFont.systemFont(ofSize: 13)
        return lab
    }()
    let addressLab:UILabel = {
        let lab = UILabel()
        lab.textColor = UIColor.gray
        lab.font = UIFont.systemFont(ofSize: 13)
        return lab
    }()
    
   lazy var deleteBtn: UIButton = {
        let btn = UIButton()
        btn.setImage(UIImage(named: "clear"), for: .normal)
        btn.actionBlock = { [weak self] _ in
        self!.deleteBlock?()
        }
        return btn
    }()
    
    var data: String?
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = UIColor.clear
        self.selectionStyle = UITableViewCell.SelectionStyle.none
        makeConstrait()
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func makeConstrait(){
        self.addSubview(bgView)
        bgView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-15)
            make.bottom.equalToSuperview()
            make.top.equalToSuperview().offset(13)
        }
        bgView.addSubview(nameLab)
        bgView.addSubview(phoneLab)
        bgView.addSubview(addressLab)
        bgView.addSubview(deleteBtn)
        
        nameLab.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(17)
            make.top.equalToSuperview().offset(19)
        }
        phoneLab.snp.makeConstraints { (make) in
            make.centerY.equalTo(nameLab)
            make.left.equalTo(nameLab.snp.right).offset(15)
        }
        addressLab.snp.makeConstraints { (make) in
            make.left.equalTo(nameLab)
            make.top.equalTo(nameLab.snp.bottom).offset(5)
            make.bottom.equalToSuperview().offset(-17)
            make.right.equalToSuperview().offset(-17)
        }
        deleteBtn.snp.makeConstraints { (make) in
            make.centerY.equalTo(nameLab)
            make.right.equalToSuperview().offset(-17)
        }
        
        
    }
    
    func configUI(dataStr: String) {
        nameLab.text = "王二麻子"
        phoneLab.text = "13123123"
        addressLab.text = "等祭扫就佛教放假时间"
        data = dataStr
    }
    

}
